package com.huike.web.controller.system;


import com.huike.clues.service.ISysMenuService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.TreeSelect;
import com.huike.common.core.domain.entity.SysMenu;
import com.huike.common.core.page.TableDataInfo;
import com.huike.web.result.RoleDeptTreeAjaxResult;
import com.huike.web.result.RoleMenuTreeAjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController {
    @Resource
    private ISysMenuService menuService;

    /**
     * 获取菜单列表
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SysMenu sysMenu){
     List<SysMenu> sysMenuList= menuService.list(sysMenu);
     return AjaxResult.success(sysMenuList);
    }

    /**
     * 菜单插入
     * @param sysMenu
     * @return
     */

    @PostMapping
    public AjaxResult menuInsert(@RequestBody SysMenu sysMenu){
       menuService.menuInsert(sysMenu);
        return AjaxResult.success();
    }

    /**
     *根据菜单编号获取详细信息
     * @return
     */
    @GetMapping("/{menuId}")
    public AjaxResult selectBymenuId(@PathVariable Integer menuId){
      SysMenu sysMenu=menuService.selectBymenuId(menuId);
      return AjaxResult.success(sysMenu);
    }

    /**
     * 修改菜单
     * @param sysMenu
     * @return
     */

    @PutMapping
    public AjaxResult menuUpdata(@RequestBody SysMenu sysMenu){
        menuService.menuUpdata(sysMenu);
        return AjaxResult.success();
    }

    /**
     * 获取菜单下拉树列表
     * @param sysMenu
     * @return
     */
    @GetMapping("/roleMenuTreeselect/{roleId}")
    public RoleMenuTreeAjaxResult roleMenuTreeselect(SysMenu sysMenu){
        List<Integer> menus=menuService.findRoleMenus(sysMenu.getMenuId());
        RoleMenuTreeAjaxResult roleMenuTreeAjaxResult=new RoleMenuTreeAjaxResult(200,"成功");
        roleMenuTreeAjaxResult.setMenus(menuService.findTreeDept());
        roleMenuTreeAjaxResult.setCheckedKeys(menus);
        return roleMenuTreeAjaxResult;
    }

    /**
     * 删除
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    public AjaxResult menuDelete(@PathVariable Integer menuId){
        menuService.menuDelete(menuId);
        return AjaxResult.success();
    }

      @GetMapping("/treeselect")
      public AjaxResult<TreeSelect> Treeselect(SysMenu sysMenu){
          List<TreeSelect> treeDept = menuService.findTreeDept();
          return AjaxResult.success(treeDept);
    }

}
